﻿using System;
using ChartInfrastructure;
using PerformanceMonitor.Charts;

namespace PerformanceMonitor
{
    public partial class Report : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            var path = Request.Params["path"];

            var reader = new SettingsReader();
            var chartsSettings = reader.GetSettings(path);

            foreach (var settings in chartsSettings.Charts)
            {
                var chartControl = (Graph)LoadControl("~/Graph.ascx");

                chartControl.Title = settings.Title;
                chartControl.SubTitle = settings.File;
                chartControl.YAxisName = settings.YAxisName;
                chartControl.StartDateTime = chartsSettings.StartDateTime;
                chartControl.PointInterval = chartsSettings.PointInterval;

                var lines = reader.GetLines(settings.FilePath);

                foreach (var lineData in lines)
                {
                    chartControl.Lines.Add(new ChartLine()
                    {
                        Name = lineData.Title,
                        Data = lineData.Points
                    });
                }

                form1.Controls.Add(chartControl);
            }
        }
    }
}
